from bases.work_wenxin_base import WorkWeiXinBase

"""通讯录页面所属接口类"""


class AddressBookPage(WorkWeiXinBase):

    def create_member(self, params: dict, extract=None, proxies=None):
        desc = '企业微信-通讯录-创建成员接口'
        route = 'cgi-bin/user/create'
        req_temp = '../temps/address_book/create_member.yml'
        schema_tmp = '../schemas/address_book/create_member.yml'
        # proxies = {'http': 'http://localhost:8888', 'https': 'http://localhost:8888'}
        headers = self.header_process(params)
        resp = self.send_post(desc, self.route_add_token(route), json_=self.json_temp_complete(req_temp, params, True),
                              proxies=proxies, headers=headers)
        self.update_extracts(resp, extract)
        self.json_schema(resp, schema_tmp, params)
        return resp

    def get_member(self, userid, extract=None):
        desc = '企业微信-通讯录-读取成员接口'
        route = 'cgi-bin/user/get'
        params = {'userid': userid}
        schema_tmp = '../schemas/address_book/get_member.json'
        resp = self.send_get(desc, self.route_add_token(route), params=params)
        self.update_extracts(resp, extract)
        self.json_schema(resp, schema_tmp)
        return resp
